﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Weblications.Sango.Protocol.player;
using Pixysoft.Framework.Reflection;
using Pixysoft.Weblications.Sango.Constant;
using Pixysoft.Weblications.Sango.Dao;
using Pixysoft.Weblications.Sango.Protocol;
using Pixysoft.Weblications.Sango.Environment;

namespace Pixysoft.Weblications.Sango.Command.section_rvr
{
    partial class SangoSectionRvrHandler
    {
        public sectionrvr_submit sectionrvr_submit(string code)
        {
            string userCode = SangoManager.Authentication();
            sectionrvr_submit response = ReflectionManager.CreatePojo<sectionrvr_submit>();
            response.Succeed = false;

            Entities.Usr_Sectionbattle rvr = UsrSectionBattleDao.GetSectionBattle(code);
            if (rvr.Battlestatus != GeneralStatusCollection.OPEN)
            {
                response.Message = "奖励已经领取";
                return response;
            }

            IEntityNoebeTransaction command = SettingHelper.EntityTransaction;
            command.Begin(delegate()
            {
                Entities.Usr_Profile profile = UsrProfileDao.getUsrProfile(userCode);

                if (UsrProfileDao.increaseFamevalue(profile, rvr.Famevalue))
                {
                    Entities.Usr_Section section = UsrSectionDao.GetSection(userCode);

                    section.Scaletypecode = SysSectionScaleHelper.SearchByFamevalue(profile.Famevalue).Scaletypecode;

                    command.Update(section);
                }

                command.Update(profile);

                rvr.Battlestatus = GeneralStatusCollection.CLOSE;
                command.Update(rvr);

                command.Commit();

                response.profile = UsrProfileFacade.ToProfile(profile);
            });

            response.Succeed = true;
            return response;
        }
    }

    public interface sectionrvr_submit : ISangoResponse
    {
        player_profile profile { get;set;}
    }
}
